#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <signal.h>

// callback
void on_terminal_resize(int signum) {
    struct winsize ws;
    ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws);
    printf("rows=%d, cols=%d, total=%d\n", ws.ws_row, ws.ws_col, ws.ws_row * ws.ws_col);
}

int main()
{
    signal(SIGWINCH, on_terminal_resize);

    struct winsize ws;
    ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws);
    printf("rows=%d, cols=%d, total=%d\n", ws.ws_row, ws.ws_col, ws.ws_row * ws.ws_col);

    while (1)
        sleep(1);

    return 0;
}
